using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPContactPersonsService
    {
        ISession session;

        public MRPContactPersonsService(ISession session)
        {
            this.session = session;
        }
        public MRPContactPersonsService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpcontactpersons(MRPContactPersons mrpcontactpersonsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpcontactpersonsX);
            tx.Commit();
        }

        public void UpdateMrpcontactpersons(MRPContactPersons mrpcontactpersonsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpcontactpersonsX);
            tx.Commit();
        }

        public void DeleteMrpcontactpersons(MRPContactPersons mrpcontactpersonsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpcontactpersonsX);
            tx.Commit();
        }

        public IList<MRPContactPersons> GetAllMrpcontactpersons(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPContactPersons");
            IList<MRPContactPersons> list = query.List<MRPContactPersons>();
            if (evict)
            {
                foreach (MRPContactPersons s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPContactPersons GetAllMrpcontactpersonsByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPContactPersons as c where c.Contactpersoncode= :x");
            query.SetString("x", id);
            MRPContactPersons s = (MRPContactPersons)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPContactPersons> GetMrpcontactpersonsByQuery(IQuery query, Boolean evict)
        {
            IList<MRPContactPersons> list = query.List<MRPContactPersons>();
            if (evict)
            {
                foreach (MRPContactPersons s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
